package com.pym.controller;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.pym.common.ResultMsg;
import com.pym.entity.PymWpxx;
import com.pym.enums.ResultEnum;
import com.pym.service.PymWpdjService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ClassName
 * @Description TODO
 * @Author wmj
 * @Date 2021/8/21
 * @Version 1.0
 **/
@Slf4j
@RestController
public class PymWpdjController {
    @Autowired
    private PymWpdjService pymWpdjService;

    @PostMapping(value = "api/wpdjService")
    public ResultMsg wpdjService(@RequestParam(required = true) String pymWpxx,
                                 @RequestParam(value = "czrName",required=false)  String czrName,
                                 @RequestParam(value = "czrIdCard",required=false)  String czrIdCard,
                                 @RequestParam(value = "domain",required=false)  String domain,
                                 @RequestParam(value = "path",required=false)  String path) throws JsonProcessingException {

        System.out.println(pymWpxx);
        System.out.println(czrName);

        ObjectMapper mapper = new ObjectMapper();
        //将Json转化为实体对象
        PymWpxx wpxx = mapper.readValue(pymWpxx, PymWpxx.class);
        int i = pymWpdjService.wpdjService(wpxx,czrName,czrIdCard,domain, path);
        if (i == 1) {
            return new ResultMsg(ResultEnum.SUCCESS);
        }
        return new ResultMsg(ResultEnum.WPDJ_INSERT_ERROR);
    }


}
